package com.xcf.client;


import com.xcf.center.ZookeeperRegisterConfig;
import com.xcf.center.client.ServerConfig;
import com.xcf.center.client.ServerManager;
import com.xcf.center.client.ServerWatcher;
import com.xcf.center.server.RegisterConfig;
import com.xcf.pojo.User;
import com.xcf.service.IUserService;

import java.util.Collections;

public class ClientBootStrap {

    public static void main(String[] args) throws Exception {
        ServerConfig config = new ServerConfig();
        ZookeeperRegisterConfig zkConfig = new ZookeeperRegisterConfig();
        zkConfig.setZookeeperIP("127.0.0.1");
        zkConfig.setZookeeperPort(2181);
        config.setRegisterConfig(zkConfig);
        config.setNameSpaces(Collections.singleton("/test-server"));
        ServerManager serverManager = new ServerManager(new WorkBalanceHandler());
        RpcConsumer rpcConsumer = new RpcConsumer(serverManager);
        ServerWatcher watcher = new ServerWatcher(config, serverManager);
        watcher.init();
        int i = 1;
        while (true) {
            Thread.sleep(2000);
            User user = new User();
            user.setName("張三");
            IUserService userService = rpcConsumer.createProxy("/test-server", IUserService.class, "userService");
            System.out.println(i + " userService = " + userService.register(user));
            i++;
            try {
                System.out.println(i + " " + userService.sayHello("Hello Server"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }


}
